package Verifier.ByteTree;

/**
 * Functions in this class were used to check the class ByteTree
 * ALL ARE NOT IN USE.
 * 
 * @author ofekp
 */
public class GeneralUtils {

	/**
	 * @param b a byte
	 * @return 	<pre>a binary string that represent that byte
	 * 			if the byte represent a negative number it is
	 * 			parsed that way.
	 * 			for example: a byte that contains -85 will generate
	 * 			the string "10101011"</pre>
	 */
	public static String byteToBinaryString(byte b) {
		boolean isPos = (b >= 0);
		String res = "";
		for (int i = 0; i < 8; i++) {
			res = Math.abs(b % 2) + res;
			b /= 2;
		}
		if (isPos)
			return res;
		
		// for negative number
		int i = 7;
		String res_neg = "";
		while (res.charAt(i) != '1' && i >= 0) {
			res_neg += '0';
			i--;
		}
		res_neg = '1' + res_neg;
		i--;
		while(i >= 0) {
			if (res.charAt(i) == '0')
				res_neg = '1' + res_neg;
			else
				res_neg = '0' + res_neg;
			i--;
		}
		return res_neg;
	}
	
}
